import 'package:dynamic_forms/dynamic_forms.dart';
import 'package:meta/meta.dart';

class DyFormFieldList extends FormElement {
  static const String childrenPropertyName = "children";
  static const String attributePropertyName = "attribute";

  List<FormElement> get children => properties[childrenPropertyName].value;
  Stream<List<FormElement>> get childrenChanged =>
      properties[childrenPropertyName].valueChanged;
  String get attribute => properties[attributePropertyName].value;
  Stream<String> get attributeChanged =>
      properties[attributePropertyName].valueChanged;

  void fillFormFieldList(
      {@required String id,
        @required ElementValue<FormElement> parent,
        @required ElementValue<bool> isVisible,
        @required ElementValue<List<FormElement>> children,
        @required ElementValue<String> attribute}) {
    fillFormElement(id: id, parent: parent, isVisible: isVisible);
    registerElementValue(childrenPropertyName, children);
    registerElementValue(attributePropertyName, attribute);
  }

  @override
  FormElement getInstance() {
    return DyFormFieldList();
  }
}